define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/bill/index' + location.search,
                    add_url: 'user/bill/add',
                    edit_url: 'user/bill/edit',
                    del_url: 'user/bill/del',
                    multi_url: 'user/bill/multi',
                    import_url: 'user/bill/import',
                    table: 'user_bill',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport:false,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'nickname', title: "昵称",operate: false},
                        {field: 'u.nickname', title: "昵称",visible: false},
                        {field: 'name', title: "姓名",operate: false},
                        {field: 'u.name', title: "姓名",visible: false},
                        {field: 'name', title: "姓名",operate: false},
                        {field: 'mobile', title: "电话",operate: false},
                        {field: 'u.mobile', title: "电话",visible: false},
                        {field: 'money', title: "变动金额", operate:'BETWEEN'},
                        {field: 'before', title: "变更前余额", operate:'BETWEEN'},
                        {field: 'after', title: "变更后余额", operate:'BETWEEN'},

                        {field: 'source', title: "来源", searchList: {0:"提现",1:"充值",2:"保障金",3:"佣金",4:"购买课程",5:"推荐奖"}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
